#ifndef BUSINESSMSGHANDLER_H
#define BUSINESSMSGHANDLER_H

#include "Router/router.h"
#include <nlohmann/json.hpp>


class BusinessMsgHandler
{
public:
    // 删除拷贝构造函数和拷贝赋值操作符
    BusinessMsgHandler(BusinessMsgHandler const&) = delete;
    BusinessMsgHandler& operator=(BusinessMsgHandler const&) = delete;
    // 提供一个全局唯一的接口
    static BusinessMsgHandler& getInstance() {
        static BusinessMsgHandler instance;
        return instance;
    }

    // init the modules
    void init();

    // handle message
    void handleMsg(std::shared_ptr<Protocol> protocol, const hv::SocketChannelPtr& channel);

    // get json of message
    static nlohmann::json getJsonOfMessage(std::shared_ptr<Protocol> protocol);



private:
    // init the server related setting
    void RecvServerConfig(std::shared_ptr<Protocol> protocol);
    // receive a reply of a apply
    void RecvReplyOfApply(std::shared_ptr<Protocol> protocol);
    // receive a message from a user
    void RecvUserMessage(std::shared_ptr<Protocol> protocol);
    // receive a message from a group
    void RecvGroupMessage(std::shared_ptr<Protocol> protocol);
    // receive a offline message from a user
    void RecvOfflineUserMessage(std::shared_ptr<Protocol> protocol);
    // receive a unique id
    void RecvUniqueID(std::shared_ptr<Protocol> protocol);
    // receive a confirmation to a block file
    void RecvConfirmOfFileBlock(std::shared_ptr<Protocol> protocol);
    // receive all the file of server
    void RecvAllFile(std::shared_ptr<Protocol> protocol);
    // update UserList
    void updateUserList(std::shared_ptr<Protocol> protocol);
    Router msgRouter;

    BusinessMsgHandler();


};

#endif // BUSINESSMSGHANDLER_H
